<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

	<link type="text/css" rel="stylesheet" href="../resources/css/bootstrap.min.css" />
	<link type="text/css" rel="stylesheet" href="../resources/css/style.css" />
	<script type="text/javascript" src="../resources/js/jquery.js"></script>
	<script type="text/javascript" src="../resources/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../resources/js/jquery-ui.js"></script>
	<link type="text/css" rel="stylesheet" href="../resources/css/jquery-ui.css" />
	
	<link type="text/css" rel="stylesheet" href="../resources/css/jquery.ui.timepicker.css" />
	<script type="text/javascript" src="../resources/js/jquery.ui.core.min.js"></script>
	<script type="text/javascript" src="../resources/js/jquery.ui.widget.min.js"></script>
	<script type="text/javascript" src="../resources/js/jquery.ui.tabs.min.js"></script>
	<script type="text/javascript" src="../resources/js/jquery.ui.position.min.js"></script>
	<script type="text/javascript" src="../resources/js/jquery.ui.timepicker.js"></script>
	
	<script type="text/javascript">
	$(document).ready(function(){
		$("#table #rows").click(function(){
			   $(this).addClass('selected').siblings().removeClass('selected');    
			   var idcongvan = $(this).find('td:eq(0)').html();
			   var trichyeu = $(this).find('td:eq(1)').html();
			   var filedinhkem = $(this).find('td:eq(2)').text();
			   var ngaynhan = $(this).find('td:eq(3)').html();
			   var noigui = $(this).find('td:eq(4)').html();
			  	$('#kyhieuCV_s').val(idcongvan);
			  	$('#trichYeu_s').val(trichyeu);
			  	$('#fileDinhKem_s').val(filedinhkem);
			  	$('#datepicker_s').val(ngaynhan);
				$('#noiGui_s').val(noigui);
				
				$('#btnDelete').attr('href', 'xoacongvan/'+idcongvan);
				  
			  })
	});	
	</script>

<!-- MODAL THEM CONG VAN DEN -->



<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Thêm Công Văn Đến</h4>
</div>
<div class="modal-body">
 	<form action="upload"  method="post" id="path" class="form-horizontal" enctype="multipart/form-data">
		<div class="form-group">
			<label for="kyhieuCV" class="col-lg-3 control-label">Ký hiệu công văn</label>
			<div class="col-lg-9">
			<input class="form-control" id="kyhieuCV" name="idcongvan" placeholder="Ký hiệu công văn" type="text">
			</div>
		</div><!-- end form-group-->

		<div class="form-group">
			<label for="trichYeu" class="col-lg-3 control-label">Trích yếu</label>
			<div class="col-lg-9">
			<textarea class="form-control" rows="3" id="trichYeu" name="trichyeu"></textarea>
			</div>
		</div>
		<div class="form-group">
			<label class="col-lg-3 control-label">File đính kèm</label>
			<div class="col-lg-9">
 			<div class="input-group">
 			<span class="input-group-btn">
			<span class="btn btn-primary btn-file">
			Browse <input type="file" name="file" id="file">
			</span>
			</span>
			<input type="text" id="fileDinhKem" name="filedinhkem" class="form-control" readonly>
			</div>  
			</div>
		</div> 

		  <div class="form-group">
			<label for="ngayNhan" class="col-lg-3 control-label">Ngày Nhận</label>
			<div class="col-lg-9">
			 <input class="form-control" type="text" name="ngaynhan" id="datepicker" placeholder="Ngày Nhận">
			</div>
		</div><!--end form-group  -->

		<div class="form-group">
			<label for="noiGui" class="col-lg-3 control-label">Nơi gửi</label>
			<div class="col-lg-9">
			<input class="form-control" id="noiGui" name="noigui" placeholder="Nơi gửi" type="text">
			</div>
		</div><!--end form-group  -->
		
		<button type="button" class="btn btn-default" data-dismiss="modal">Đóng</button>
		<button type="submit" class="btn btn-primary">Lưu</button>

	</form> 
</div><!-- END modal-body -->
</div><!-- END modal-content -->
</div><!-- END modal-dialog modal-lg -->
</div><!-- END modal fade bs-example-modal-lg -->


<!-- MODAL SUA CONG VAN DEN -->

<div class="modal fade suacongvan" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Sữa Công Văn Đến</h4>
</div>
<div class="modal-body">
	<form action="updatecongvanden"  method="post" id="path" class="form-horizontal" accept-charset="UTF-8"  enctype="multipart/form-data">
		<div class="form-group">
			<label for="kyhieuCV" class="col-lg-3 control-label">Ký hiệu công văn</label>
			<div class="col-lg-9">
			<input class="form-control" id="kyhieuCV_s" name="idcongvan" placeholder="Ký hiệu công văn" readonly type="text">
			</div>
		</div><!-- end form-group-->

		<div class="form-group">
			<label for="trichYeu" class="col-lg-3 control-label">Trích yếu</label>
			<div class="col-lg-9">
			<textarea class="form-control" rows="3" id="trichYeu_s" name="trichyeu"></textarea>
			</div>
		</div>
		<div class="form-group">
			<label class="col-lg-3 control-label">File đính kèm</label>
			<div class="col-lg-9">
			<div class="input-group">
			<span class="input-group-btn">
			<span class="btn btn-primary btn-file">
			Browse <input type="file">
			</span>
			</span>
			<input type="text" id="fileDinhKem_s" name="filedinhkem" class="form-control" disabled>
			</div>
			</div>
		</div>

		<div class="form-group">
			<label for="ngayNhan" class="col-lg-3 control-label">Ngày Nhận</label>
			<div class="col-lg-9">
			 <input class="form-control" type="text" name="ngaynhan" id="datepicker_s" placeholder="Ngày Nhận">
			</div>
		</div><!-- end form-group-->

		<div class="form-group">
			<label for="noiGui" class="col-lg-3 control-label">Nơi gửi</label>
			<div class="col-lg-9">
			<input class="form-control" id="noiGui_s" name="noigui" placeholder="Nơi gửi" type="text">
			</div>
		</div><!-- end form-group-->
		<button type="button" class="btn btn-default" data-dismiss="modal">Đóng</button>
		<button type="submit" class="btn btn-primary">Lưu</button>

	</form>
</div><!-- END modal-body -->
</div><!-- END modal-content -->
</div><!-- END modal-dialog modal-lg -->
</div><!-- END modal fade bs-example-modal-lg -->
<!-- END MODAL SUA CONG VAN DEN -->

<!-- MODAL xoa cong van-->
<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Xóa nhân viên</h4>
</div>
<div class="modal-body">
	<h1 style="color: red;">Bạn có chắc chắn muốn xóa không ??</h1>
</div><!-- END modal-body -->
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Hủy</button>
    <a class="btn btn-primary" id="btnDelete" >Xóa</a>
</div>
</div><!-- END modal-content -->
</div><!-- END modal-dialog modal-lg -->
</div><!-- END modal fade bs-example-modal-lg -->
<!-- END MODAL XOA cong van-->
	
    
    <c:choose>
	<c:when test="${!empty err}">
			<a class="btn btn-primary" href="<c:url value='/thuky' />">Trở về</a>
			<div class="alert alert-dismissable alert-danger">
			  <button type="button" class="close" data-dismiss="alert">×</button>
			  <strong>Công văn đã được phân công. Không thể xóa !!!</strong>
			</div>	
	</c:when>
		<c:otherwise>	
		<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Thêm</button>	
			<c:if test="${!empty listCongVan}">
	<table class="table table-hover" id="table">
		<tr>
			<th width="80">Mã Công Văn</th>
			<th width="80">Trích Yếu</th>
			<th width="120">File Đính Kèm</th>
			<th width="120">Ngày Nhận</th>
			<th width="120">Nơi Gửi</th>
			<th width="80">Sửa</th>
			<th width="80">Xóa</th>
			
		</tr>
		<c:forEach items="${listCongVan}" var="congvan">
			<c:if test="${!empty congvan.congvanden.idCongVanDen}">
			<tr id="rows">
				<td>${congvan.congvanden.idCongVanDen}</td>
				<td>${congvan.trichYeu}</td>
				<td><a id="filedinhkem" href="download/${congvan.congvanden.idCongVanDen}">${congvan.fileName}</a></td>
				<td><fmt:formatDate value="${congvan.congvanden.ngayNhan}" pattern="dd-MM-yyyy" /></td>
				<td>${congvan.congvanden.noiGui}</td>
				<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target=".suacongvan">Sửa</button></td>
				<td><a class="btn btn-primary" data-toggle="modal" href="#delete">Xóa</a></td>
			 </tr>
			 </c:if>
		</c:forEach>
	</table>
</c:if>	
		</c:otherwise>
	</c:choose>
 

